home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
hity wydania
/
Bank smakow
/
BankSmakow.air
/
BankSmakow.swf
/
scripts
/
com
/
makingwaves
/
components
/
CheckBoxTreeItemRenderer.as
next >
Wrap
Text File
|
2009-12-16
|
8KB
|
236 lines
package com.makingwaves.components
{
import com.makingwaves.vo.FridgeProduct;
import com.makingwaves.vo.Product;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
import mx.controls.CheckBox;
import mx.controls.treeClasses.TreeItemRenderer;
import mx.controls.treeClasses.TreeListData;
import mx.events.TreeEvent;
public class CheckBoxTreeItemRenderer extends TreeItemRenderer
{
public static const ITEM_CHECK:String = "itemCheck";
protected var _checkbox:CheckBox;
public function CheckBoxTreeItemRenderer()
{
super();
this.useHandCursor = true;
this.buttonMode = true;
this.addEventListener(MouseEvent.ROLL_OVER,onMouseOver);
this.addEventListener(MouseEvent.ROLL_OUT,onMouseOut);
}
private function setChildControl() : void
{
if(_checkbox == null)
{
_checkbox = new CheckBox();
this.addEventListener(MouseEvent.CLICK,onItemClick);
this.mouseChildren = false;
addChild(_checkbox);
}
label.styleName = "Ingredient";
}
private function onMouseOut(param1:Event) : void
{
this.transform.colorTransform = new ColorTransform();
}
override protected function commitProperties() : void
{
super.commitProperties();
if(data != null && data is Product)
{
_checkbox.selected = (data as FridgeProduct).selected;
}
}
private function setParentControl() : void
{
if(_checkbox != null)
{
if(this.getChildByName(_checkbox.name) != null)
{
this.removeChild(_checkbox);
}
_checkbox = null;
}
this.addEventListener(MouseEvent.CLICK,onItemClick);
this.mouseChildren = false;
label.styleName = "";
}
public function get checkBox() : CheckBox
{
return _checkbox;
}
override public function set data(param1:Object) : void
{
super.data = param1;
if(param1 != null)
{
if(!TreeListData(super.listData).hasChildren)
{
setChildControl();
}
}
}
private function onItemClick(param1:MouseEvent) : void
{
var _loc2_:TreeEvent = null;
if(this.enabled == false)
{
return;
}
if(data != null && data is Product)
{
if(!(param1.currentTarget is CheckBox))
{
_checkbox.selected = !_checkbox.selected;
}
(data as FridgeProduct).selected = _checkbox.selected;
_loc2_ = new TreeEvent(ITEM_CHECK,true);
_loc2_.item = data;
dispatchEvent(_loc2_);
}
else
{
this.disclosureIcon.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN));
}
}
override protected function updateDisplayList(param1:Number, param2:Number) : void
{
var _loc3_:Number = NaN;
var _loc4_:String = null;
if(super.listData != null && !TreeListData(super.listData).hasChildren)
{
setChildControl();
super.updateDisplayList(param1,param2);
_loc3_ = !!data ? Number((listData as TreeListData).indent) : Number(0);
if(disclosureIcon)
{
disclosureIcon.x = _loc3_;
_loc3_ = disclosureIcon.x + disclosureIcon.width;
disclosureIcon.setActualSize(disclosureIcon.width,disclosureIcon.height);
disclosureIcon.visible = !!data ? Boolean((listData as TreeListData).hasChildren) : false;
}
if(icon)
{
icon.x = _loc3_;
_loc3_ = icon.x + icon.measuredWidth;
icon.setActualSize(icon.measuredWidth,icon.measuredHeight);
}
if(checkBox)
{
_checkbox.x = _loc3_;
_loc3_ = checkBox.x + checkBox.measuredWidth;
checkBox.setActualSize(checkBox.measuredWidth,checkBox.measuredHeight);
}
label.x = _loc3_;
label.setActualSize(label.getExplicitOrMeasuredWidth(),measuredHeight);
if((_loc4_ = getStyle("verticalAlign")) == "top")
{
label.y = 0;
_checkbox.y = 0;
if(icon)
{
icon.y = 0;
}
if(disclosureIcon)
{
disclosureIcon.y = 0;
}
}
else if(_loc4_ == "bottom")
{
label.y = param2 - label.height + 2;
_checkbox.y = param2 - checkBox.height + 2;
if(icon)
{
icon.y = param2 - icon.height;
}
if(disclosureIcon)
{
disclosureIcon.y = param2 - disclosureIcon.height;
}
}
else
{
label.y = (param2 - label.height) / 2;
checkBox.y = (param2 - checkBox.height) / 2;
if(icon)
{
icon.y = (param2 - icon.height) / 2;
}
if(disclosureIcon)
{
disclosureIcon.y = (param2 - disclosureIcon.height) / 2;
}
}
}
else
{
setParentControl();
super.updateDisplayList(param1,param2);
}
}
private function onMouseOver(param1:Event) : void
{
var _loc2_:ColorTransform = new ColorTransform();
_loc2_.color = 16610051;
this.transform.colorTransform = _loc2_;
}
override protected function measure() : void
{
var _loc1_:Number = NaN;
super.measure();
if(_checkbox != null)
{
_loc1_ = !!data ? Number((listData as TreeListData).indent) : Number(0);
if(disclosureIcon)
{
_loc1_ += disclosureIcon.width;
}
if(icon)
{
_loc1_ += icon.measuredWidth;
}
if(label.width < 4 || label.height < 4)
{
label.width = 4;
label.height = 16;
}
if(isNaN(explicitWidth))
{
_loc1_ += label.getExplicitOrMeasuredWidth();
_loc1_ += _checkbox.getExplicitOrMeasuredWidth();
measuredWidth = _loc1_;
measuredHeight = Math.max(_checkbox.getExplicitOrMeasuredHeight(),label.getExplicitOrMeasuredHeight());
}
else
{
label.width = Math.max(explicitWidth - (_loc1_ + _checkbox.getExplicitOrMeasuredWidth()),4);
measuredHeight = Math.max(_checkbox.getExplicitOrMeasuredHeight(),label.getExplicitOrMeasuredHeight());
if(icon && icon.measuredHeight > measuredHeight)
{
measuredHeight = icon.measuredHeight;
}
}
}
}
}
}